package cn.dlc.com.graph;

import lombok.Data;

/**
 * @author 邓立川
 * @date 2021/3/31 7:02
 * @desc 有权无向图的边
 */
@Data
public class Edge implements Comparable<Edge>{

    private int v;
    private int w;
    private double weight;

    public Edge(int v, int w, double weight){
        this.v = v;
        this.w = w;
        this.weight = weight;
    }

    public double weight(){
        return this.weight;
    }

    // 随便获取一条边
    public int either(){
        return this.v;
    }

    // 获取另外一条边
    public int other(int vertex) {
        if(this.v == vertex) {
            return w;
        } else {
            return v;
        }
    }

    @Override
    public int compareTo(Edge o) {
        if(this.getWeight() > o.getWeight()) {
            return 1;
        } else if(this.getWeight() == o.getWeight()) {
            return 0;
        } else {
            return -1;
        }
    }
}
